class Solution {
    public int minimumDeleteSum(String s1, String s2) {
         int n = s1.length() ;
         int m = s2.length() ;
         int[][] dp = new int[n+1][m+1];
         char[] a1 =s1.toCharArray() ;
         char[] b1 = s2.toCharArray() ;
         for(int i=1 ; i<= n ; i ++){
            for(int j=1 ; j<=m ; j ++){
                dp[i][j] = Math.max(dp[i-1][j] , dp[i][j-1]);
                if(a1[i-1] == b1[j-1]){
                    dp[i][j] = Math.max(dp[i-1][j-1]+a1[i-1] , dp[i][j] );
                }
            }
         }
         int sum = 0 ;
         for(char ch : a1){
            sum += ch;
         }
         for(char ch : b1){
            sum += ch ;
         }
         return sum - dp[n][m]*2 ;
    }
}